#include "udpserver.hpp"
#include <memory>
#include "dict.hpp"
#include "inetaddr.hpp"
using namespace udpserver;
using namespace mydict;
using namespace myaddr;
std::string func(const std::string &str)
{
    std::string ret = "hello ";
    ret += str;
    return ret;
}

int main(int argc, char *argv[])
{
    // if (argc != 3)
    // {
    //     std::cout << "usage : ./udpserver ip port" << std::endl;
    //     exit(1);
    // }
    // std::string ip = argv[1];
    // uint16_t port = std::stoi(argv[2]);
    // std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(ip, port);

    if (argc != 2)
    {
        std::cout << "usage : ./udpserver port" << std::endl;
        exit(1);
    }
    uint16_t port = std::stoi(argv[1]);
    // 1. 翻译
    Dict dict;
    dict.Load();
    // 2. Addr
    // 2. 网络通信
    // std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(port);
    // std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(port, func);
    std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(port, [&dict](const std::string &word, const Addr &addr) -> std::string
                                                                    { return dict.Translate(word, addr); });

    server->Init();
    server->Start();
    return 0;
}